home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
lib
/
rstrpos.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
2KB
|
63 lines
; $Id: rstrpos.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
;
; Copyright (c) 1993-1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
FUNCTION RSTRPOS, Expr, SubStr, Pos
;+
; NAME:
; RSTRPOS
;
; PURPOSE:
; This function finds the last occurrence of a substring within
; an object string. If the substring is found in the expression,
; RSTRPOS returns the character position of the match, otherwise
; it returns -1.
;
; CATEGORY:
; String processing.
;
; CALLING SEQUENCE:
; Result = RSTRPOS(Expr, SubStr [, Pos])
;
; INPUTS:
; Expr: The expression string in which to search for the substring.
; SubStr: The substring to search for.
;
; OPTIONAL INPUTS:
; Pos: The character position before which the search is bugun.
; If Pos is omitted, the search begins at the last character
; of Expr.
;
; OUTPUTS:
; Returns the position of the substring, or -1 if the
; substring was not found within Expr.
;
; SIDE EFFECTS:
; Unlike STRPOS, Expr and SubStr must be strings.
;
; EXAMPLE:
; Expr = 'Holy smokes, Batman!' ; define the expression.
; Where = RSTRPOS(Exp, 'smokes') ; find position.
; Print, Where ; print position.
; 5 ; substring begins at position 5
; ; (the sixth character).
;
; MODIFICATION HISTORY:
; JWG, January, 1993
;-
Len = STRLEN(Expr)
IF N_ELEMENTS(Pos) EQ 0 THEN Start=0 ELSE Start = Len - Pos
; Reverse the string
RString = REVERSE(BYTE(Expr))
; Reverse the substring
RSubStr = REVERSE(BYTE(SubStr))
SubPos = STRPOS(STRING(RString),STRING(RSubStr),Start)
IF SubPos NE -1 THEN SubPos = Len - SubPos - STRLEN(SubStr)
RETURN, SubPos
END